<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * 用户拆分操作
 */
namespace Home\Logic;
use Think\Log;
use Home\Model\CustomerModel;
/**
 * Description of UserLogic
 *
 * @author wangding
 */
class UserLogic {
    //put your code here
    
    public function __construct()
    {
        
//        $connection = array(  //正式
//            'db_type'    =>   'mysql',
//            'db_host'    =>   'rm-2ze826fhk990dt0q3mo.mysql.rds.aliyuncs.com',
//            'db_user'    =>   'fenqingbang',
//            'db_pwd'     =>   'QWEasd123',
//            'db_port'    =>    3306,
//            'db_name'    =>    'minfu_user',
//            'db_charset' =>    'utf8',
//            'db_deploy_type'=>    1,
//            'db_rw_separate'=>    true,
//            'db_debug'    =>    true,
//        );
         $connection = array(//测试
             'db_type'    =>   'mysql',
             'db_host'    =>   '127.0.0.1',
             'db_user'    =>   'root',
             'db_pwd'     =>   '',
             'db_port'    =>    3306,
             'db_name'    =>    'loan_user',
             'db_charset' =>    'utf8',
             'db_deploy_type'=>    1,
             'db_rw_separate'=>    true,
             'db_debug'    =>    true,
         );

        $this->model = new CustomerModel('customer','fb_',$connection);
    }
    
    /**
     * 获取用户id
     * @param type $mobile
     * @return type
     */
    public function findUserIDForMobile($mobile){
        $customer_id = $this->model->where(['mobile'=>$mobile])->getField('id');
        return $customer_id;
        // 检测是否存在此用户
    }
    public function findMobileForUserID($userid){
        $mobile = $this->model->where(['id'=>$userid])->getField('mobile');
        return $mobile;
    }
    
    
    /**
     * 
     * @param type $mobile
     * @return type
     */
    public function addUserMobile($mobile){
        $customer_data = [
            'mobile' => $mobile,
            'add_time' => time(),
            'update_time' => time(),
        ];
        $customer_id = $this->model->add($customer_data);
        Log::write('插入用户表SQL==='.M('customer')->getLastSql());
        
        return $customer_id;
        
    }

    /**
     * 检查手机号是否存在主表里
     * @param $mobile 手机号
     * @author wangding
     * @return integer
     */
    public function _checkMainCustomer($mobile){
        $customer_id = $this->model->where(['mobile'=>$mobile])->getField('id');
        return $customer_id ? 1 : 0;
    }

    /**
     * [getmobileall 批量获取手机号]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function getmobileall($id){
        $mobile = $this->model->field('mobile')->where(['id'=>['in',$id]])->order('id desc')->select();
        return $mobile;
    }
    
}
